/**
 * Created by Administrator on 2018-07-12.
 */
define(function (require,exports,module) {
    var sTpl = require("./purchaseOrderList.html");
    var order = require("../purchaseOrder/order.js");
    var VueComponent = Vue.extend({
        template: sTpl,
        components:{
            'orders':order
        },
        data:function () {
            return {
                see:false,
                see1:true,
                checkOrderList:{
                    buyNum:'',
                    purchaseDate:'',
                    auditStatus:''
                },
                orderListData:[
                ],
                orderParentData:{
                    showOrEdit:"show"
                },

                pickerOptions3: {
                    shortcuts: [{
                        text: '今天',
                        onClick:function(picker) {
                            picker.$emit('pick', new Date());
                        }
                    }, {
                        text: '昨天',
                        onClick:function(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24);
                            picker.$emit('pick', date);
                        }
                    }, {
                        text: '一周前',
                        onClick:function (picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', date);
                        }
                    }]
                }
            }
        },
        methods:{
            pickTime3:function (val) {
                this.stockInFormInline.stockDate = val;
            },
            addpurchaseOrder:function () {
                
            },
            findAllBuyOrder:function () {
                var $this = this;
                axios.get(basepath+"/api/purchaseMgr/findBuyOrderPo"
                ).then(function (response) {
                    $this.orderListData=response.data;
                });
            },
            seeOrder:function (scope) {
                this.see=true;
                this.see1=false;
                this.$refs.orders.orderFormInline=scope.row;
                this.$refs.orders.isShow=true;
                this.$refs.orders.isEditOrAdd=false;
                $this=this;
                this.$refs.orders.orderParentData.returnOrderParent=function () {
                    $this.see=false;
                    $this.see1=true;
                }
            },
            editOrder:function (scope) {
                this.see=true;
                this.see1=false;
                this.$refs.orders.orderFormInline=JSON.parse(JSON.stringify(scope.row));
                this.$refs.orders.isEditOrAdd=true;
                this.$refs.orders.isShow=false;
                $this=this;
                this.$refs.orders.orderParentData.returnOrderParent=function () {
                    $this.see=false;
                    $this.see1=true;
                    $this.findAllBuyOrder();
                }
            },
            findOrderList:function () {
                var $this = this;
                axios.get(basepath+"/api/purchaseMgr/checkBuyOrderPo",{
                    params: {
                        buyNum:$this.checkOrderList.buyNum,
                        purchaseDate:$this.checkOrderList.purchaseDate,
                        auditStatus:$this.checkOrderList.auditStatus
                    }}
                ).then(function (response) {
                    console.log(response);
                    $this.orderListData=response.data;
                });

            },
            addOrder:function (e) {
               this.see=true;
               this.see1=false;
                this.$refs.orders.isEditOrAdd=true;
                this.$refs.orders.isShow=false;
                this.$refs.orders.orderFormInline={
                    auditStatus:'未审核',
                    totalMoney:0.0,
                    purchaseDate:'',
                    supplier:'',
                    contacts:'',
                    phone:'',
                    interactiveAddress:'',
                    interactiveDate:'',
                    buyGoodsPos:[]
                };
                $this=this;
                this.$refs.orders.orderParentData.returnOrderParent=function () {
                    $this.see=false;
                    $this.see1=true;
                    $this.findAllBuyOrder();
                }
            },
            deleteOrder:function (scope) {
                var $this = this ;
                this.$confirm('确定删除？', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'success'
                }).then(function() {
                    axios.post(basepath+'/api/purchaseMgr/delectBuyOrderPo',scope.row)
                        .then(function (response) {
                            $this.$notify({
                                title: '已删除',
                                message: '已删除'
                            });

                            $this.findOrderList();
                        });
                })
            },
        },
        watch:{
        },
        created:function () {
            this.findAllBuyOrder();

        },
        activated:function () {
            messages.$emit('change','订单列表');
        }
    })
    module.exports=VueComponent;
    module.exports.reDefine=function (val) {
        module.exports.type=val;
        return module.exports;
    }

})

